using System;
using OracleInternal.Json.Binary;
using OracleInternal.Json.Common;

namespace OracleInternal.Json.Sql
{
	internal class OracleJsonDate : OracleJsonValue
	{
		private byte[] m_raw;

		internal OracleJsonDate(byte[] raw)
		{
			m_raw = raw;
		}

		internal OracleJsonDate(DateTime i)
		{
			m_raw = OsonPrimitiveConversions.DateTimeToDate(GetExceptionFactory(), i);
		}

		public override OracleJsonType GetOracleJsonType()
		{
			return OracleJsonType.DATE;
		}

		public override string ToJsonString()
		{
			return OracleJsonSerializer.SerializeString(GetJsonString());
		}

		internal DateTime GetDateTime()
		{
			byte[] raw = m_raw;
			return OsonPrimitiveConversions.DateToLocalDateTime(GetExceptionFactory(), raw).ToUniversalTime();
		}

		internal string GetJsonString()
		{
			return OsonPrimitiveConversions.DateToString(GetExceptionFactory(), m_raw);
		}

		internal byte[] Raw()
		{
			return m_raw;
		}

		internal OracleJsonDate getDATE()
		{
			return this;
		}

		internal IExceptionFactory GetExceptionFactory()
		{
			return OracleJsonExceptions.ORACLE_FACTORY;
		}
	}
}
